package com.yunmang.fragment.qianshou;

import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;

import com.yunmang.R;
import com.yunmang.adapter.TimeAdapter;
import com.yunmang.entity.NodeBean;
import com.yunmang.entity.TraceBean;
import com.yunmang.fragment.BaseFragment;
import com.yunmang.http.HttpUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import rx.Subscriber;

/**
 * Created by Administrator on 2017/5/10.
 */
public class SendFailFragment extends BaseFragment {
    @InjectView(R.id.lv_list)
    ListView lvList;
    @InjectView(R.id.ll_top)
    LinearLayout llTop;
    private TimeAdapter adapter;
    private Subscriber<TraceBean> subScriber;
    private List<TraceBean.ModelBean> itemList;
    private List<NodeBean> nodeList;
    @Override
    public int getLayoutId() {
        return R.layout.act_track_search;
    }

    @Override
    public void initView(View view) {
        ButterKnife.inject(this, view);
    }

    @Override
    public void initData() {
//        getTrackInfo();
    }

    private void getTrackInfo() {
        subScriber=new Subscriber<TraceBean>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                e.printStackTrace();
            }

            @Override
            public void onNext(TraceBean traceBean) {

                if(traceBean.getCode()==200){
                    itemList=traceBean.getModel();
                    fillData();
                }else{
                }
            }
        };
        HttpUtils.getInstance().getTraceInfo(subScriber,"017038000024");
    }

    private void fillData() {
        nodeList=new ArrayList<>();
        for (TraceBean.ModelBean bean:itemList) {
            NodeBean nb=new NodeBean();
            nb.notes=bean.getDescription();
            nb.actionTime=bean.getCreateTime();
            nodeList.add(nb);
        }
        adapter=new TimeAdapter(getActivity(),nodeList);
        lvList.setAdapter(adapter);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }
}
